const { baseURL } = require('./env').prod

// 专属域名
const vip = 'mcz'

module.exports = {
  request:function(url,method='GET',data={},isSubDomain=true){
    if(isSubDomain){
      url = `${baseURL}/${vip}/${url}`
    }else{
      url = `${baseURL}/${url}`
    }

    return new Promise((resolve,reject)=> {
      // 请求之前显示loding
      wx.showLoading({
        title : '正在加载中...'
      })
      wx.request({
        url,
        method,
        data,
        header : {
          "content-type" : "application/x-www-form-urlencoded"
        },
        success(res){
          wx.hideLoading()
          resolve(res.data)
        },
        fail(error){
          reject(error)
        }
      })
    })
  }
}